from GUICore.widgets import AnimatedSvgWidget
from GUICore.widgets import CircularProgress
from AppCore.SYS import *
from AppCore.Tool import *
from GUICore.widgets.combo_box import PyComboBox
from .ui_main import *
from .functions import MainFunctions, JINYEE_FUNCTIONS, SPMK_FUNCTIONS


class SetupMainWindow:
    # def __init__(self):
    #     super().__init__()
    #     self.ui = UI_MainWindow()
    #     self.ui.setup_ui(self)

    def setup_btns(self):
        if self.ui.title_bar.sender() is not None:
            return self.ui.title_bar.sender()
        elif self.ui.left_menu.sender() is not None:
            return self.ui.left_menu.sender()
        elif self.ui.left_column.sender() is not None:
            return self.ui.left_column.sender()

    def setup_gui(self):
        self.setWindowTitle(self.app_lang["SYS"]["sys_name"])
        # 去除标题栏
        if self.settings["custom_title_bar"]:
            self.setWindowFlag(Qt.FramelessWindowHint)
            self.setAttribute(Qt.WA_TranslucentBackground)
            # 添加夹点
            self.left_grip = PyGrips(self, "left", self.settings["hide_grips"])
            self.right_grip = PyGrips(self, "right", self.settings["hide_grips"])
            self.top_grip = PyGrips(self, "top", self.settings["hide_grips"])
            self.bottom_grip = PyGrips(self, "bottom", self.settings["hide_grips"])
            self.top_left_grip = PyGrips(self, "top_left", self.settings["hide_grips"])
            self.top_right_grip = PyGrips(
                self, "top_right", self.settings["hide_grips"]
            )
            self.bottom_left_grip = PyGrips(
                self, "bottom_left", self.settings["hide_grips"]
            )
            self.bottom_right_grip = PyGrips(
                self, "bottom_right", self.settings["hide_grips"]
            )
            # 添加标题描述
            self.ui.title_bar.set_title(self.app_lang["UI"]["ui_HomePage"])
        for left_btns in self.menu_left.data.values():
            self.ui.left_menu.add_menus(left_btns)
        self.ui.left_menu.clicked.connect(self.btn_clicked)
        self.ui.left_menu.released.connect(self.btn_released)
        for title_btns in self.menu_title.data.values():
            self.ui.title_bar.add_menus(title_btns)
        self.ui.title_bar.clicked.connect(self.btn_clicked)
        self.ui.title_bar.released.connect(self.btn_released)

        self.ui.left_column.clicked.connect(self.btn_clicked)
        self.ui.left_column.released.connect(self.btn_released)

        # 设置初始页面/设置左右列菜单
        MainFunctions.set_page(self, self.ui.load_pages.page_1)
        MainFunctions.set_left_column_menu(
            self,
            menu=self.ui.left_column.menus.menu_1,
            title="Settings Left Column",
            icon_path=Functions.set_svg_icon("icon_settings.svg"),
        )
        MainFunctions.set_right_column_menu(self, self.ui.right_column.menu_1)

        # PAGES
        # PAGE 1
        SetupMainWindow.load_page1(self)

    def load_page1(self):
        # PAGE 1 欢迎页面
        self.xiaozhi = AnimatedSvgWidget()
        self.xiaozhi.setFixedSize(125, 75)
        self.ui.load_pages.logo_layout.addWidget(
            self.xiaozhi, Qt.AlignCenter, Qt.AlignCenter
        )
        self.logo_svg = QSvgWidget(Functions.set_svg_image(self.settings["logo_home"]))
        self.ui.load_pages.logo_layout.addWidget(
            self.logo_svg, Qt.AlignCenter, Qt.AlignCenter
        )
        self.next_btn = PyPushButton(
            text=self.app_lang["UI"]["ui_Next"],
            radius=8,
            color=self.ColorPalette.text_foreground,
            bg_color=self.ColorPalette.dark_one,
            bg_color_hover=self.ColorPalette.bg_three,
            bg_color_pressed=self.ColorPalette.bg_two,
        )
        self.next_btn.setFixedSize(150, 40)
        self.next_btn.clicked.connect(lambda:MainFunctions.set_page(self, self.ui.load_pages.page_2))
        self.ui.load_pages.logo_layout.addWidget(self.next_btn)
        self.ui.load_pages.welcome_label.setText(
            self.app_lang["TEXT"]["home_page_welcome"]
        )
        self.ui.load_pages.welcome_label.setStyleSheet(
            f'font: 700 20pt "{self.settings["font"]["family"]}";'
        )

    def load_left_column_menu1(self):
        SetupMainWindow.menu1_3714(self)
        SetupMainWindow.menu_JINYEE(self)

    def resize_grips(self):
        if self.settings["custom_title_bar"]:
            self.left_grip.setGeometry(5, 10, 10, self.height())
            self.right_grip.setGeometry(self.width() - 15, 10, 10, self.height())
            self.top_grip.setGeometry(5, 5, self.width() - 10, 10)
            self.bottom_grip.setGeometry(5, self.height() - 15, self.width() - 10, 10)
            self.top_right_grip.setGeometry(self.width() - 20, 5, 15, 15)
            self.bottom_left_grip.setGeometry(5, self.height() - 20, 15, 15)
            self.bottom_right_grip.setGeometry(
                self.width() - 20, self.height() - 20, 15, 15
            )
